# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
_php=php7
pkgname=rainloop-webmail
pkgver=1.14.0
pkgrel=0
pkgdesc="Simple, modern & fast web-based email client"
url="http://www.rainloop.net"
arch="noarch"
license="AGPL-3.0-only"
depends="$_php $_php-curl $_php-iconv $_php-json $_php-dom $_php-openssl
	$_php-pdo_sqlite $_php-simplexml
	"
source="$pkgname-$pkgver.zip::https://github.com/RainLoop/rainloop-webmail/releases/download/v$pkgver/rainloop-$pkgver.zip"
options="!check" # no test suite
pkggroups="www-data"
builddir="$srcdir"/rainloop

_staticdir=usr/share/webapps/rainloop
_datadir=var/lib/rainloop
_configdir=etc/rainloop

package() {
	mkdir -p \
		"$pkgdir"/$_staticdir \
		"$pkgdir"/$_datadir \
		"$pkgdir"/$_configdir
	mv "$srcdir"/rainloop/* "$pkgdir"/$_staticdir
	mv "$pkgdir"/$_staticdir/v/$pkgver/index.php.root \
		"$pkgdir"/$_staticdir/index.php

	# put config/dynamic data into /var
	mv "$srcdir"/data "$pkgdir"/$_datadir/data
	ln -s /$_datadir/data "$pkgdir"/$_staticdir/data

	# code wants to run from "rainloop" dir
	ln -s . "$pkgdir"/$_staticdir/rainloop

	# setup config dirs into /etc
	install -d -m770 -g www-data \
		"$pkgdir"/$_configdir/configs \
		"$pkgdir"/$_configdir/domains \
		"$pkgdir"/$_datadir/data/_data_/_default_
	ln -s /$_configdir/configs "$pkgdir"/$_datadir/data/_data_/_default_/configs
	ln -s /$_configdir/domains "$pkgdir"/$_datadir/data/_data_/_default_/domains

	# allow webserver to write config and temp files
	chown :www-data "$pkgdir"/$_datadir/data "$pkgdir"/$_configdir
	chmod 770 "$pkgdir"/$_datadir/data "$pkgdir"/$_configdir
}

sha512sums="effc8de581252081d4934ef2087c5a9a26c58757fd55bb8cd98f43367779ac21215689ad8b6a32d321afb3ef8e53c2e49b9cbb04495819723fedcfa8752ebb7c  rainloop-webmail-1.14.0.zip"
